<?php
if(empty($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	echo '<script type="text/javascript">alert("题号应该是一个数字…");history.back();</script>';
}
require_once 'mysql_conn_3asY&AKj0qB1.php';
$problem_id = escape_data($_REQUEST['id']);
$query = "SELECT * FROM problems WHERE id = $problem_id;";
$result = @mysqli_query($NDSOJ_dbc, $query);
if (!$result) {
	echo '呃，看起来出了点小问题…请尽快联系我们。我们的E-mail：hcc@shiyihcc.com';
	mysqli_close($NDSOJ_dbc);
	//echo mysqli_error($NDSOJ_dbc);
}
else {
	$row = mysqli_fetch_array($result);
	if (!$row) {
		echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
		echo '<script type="text/javascript">alert("题目不存在…");history.back();</script>';
	}
	mysqli_free_result($result);
	mysqli_close($NDSOJ_dbc);
}
?>
<?php
$pagename = $row['name'] . '查看题目';
include 'header.php';
?>
		<div id="nav">
			<h1><a href="index.php">NDSOJ</a></h1>
			<ul>
				<li><a href="index.php">首页</a></li>
				<?php if(!$_SESSION['login']) echo "<li><a href=\"reg.php\">注册</a></li>\n\t\t\t\t";
				?><li><a href="problem.php">题库</a></li>
				<li><a href="contest.php">比赛</a></li>
				<li><a href="discuss.php">讨论</a></li>
				<li><a href="help.php">帮助</a></li>
				<li><a href="about.php">关于</a></li>
			</ul>
		</div>
		<div id="mainbox">
			<h2><?php echo $row['name']; ?></h2>
			<p>提供题目：<?php echo $row['provider']; ?></p>
			<p>来源：<?php include 'var_source.php';
			echo "\t\t\t\t<a href=\"problem_search.php?source={$row['source']}\">{$problem_source[ $row['source'] ]}</a>";
			if($row['source_minor'])
				echo "（<a href=\"problem_search.php?source={$row['source']}&source_minor={$row['source_minor']}\">{$problem_source_minor[ $row['source_minor'] ]}</a>）\n";
			?></p>
			<?php
			if($row['background']) {
				echo <<<BACKGROUND
			<h2>题目背景</h2>
			<p>{$row['background']}</p>
BACKGROUND;
			} ?>
				<h2>问题描述</h2>
				<p><?php echo $row['description']; ?></p>
				<h2>输入文件</h2>
				<p><?php echo $row['input']; ?></p>
				<h2>输出文件</h2>
				<p><?php echo $row['output']; ?></p>
				<h2>样例输入</h2>
				<textarea rows="7" cols="64" readonly="readonly" wrap="off"><?php echo $row['sample_input']; ?></textarea>
				<h2>样例输出</h2>
				<textarea rows="5" cols="64" readonly="readonly" wrap="off"><?php echo $row['sample_output']; ?></textarea>
			<?php
			if($row['sample_hint']) {
				echo <<<HINT
			<h2>样例说明</h2>
			<p>{$row['sample_hint']}</p>
HINT;
			}
			if($row['hint']) {
				echo <<<HINT
			<h2>注释</h2>
			<p>{$row['hint']}</p>
HINT;
			} ?>
		</div>
		<div id="sidebar">
<?php
if($_SESSION['login'])
	include 'module_userbox.php';
?>
			<h2>题目信息</h2>
			<p>题号：<?php echo $problem_id; ?></p>
			<p>状态：TODO</p>
			<p>难度：<a href="problem_search.php?difficulty=<?php echo $row['difficulty']; ?>"><?php echo $row['difficulty']; ?></a></p>
			<p>类型：<a onclick="alert('<?php
				include 'var_type.php';
				echo $problem_type[ $row['type'] ];
			?>');">点击查看</a></p>
			<p>通过率：<?php echo (int)((float)$row['ac_times'] / (float)$row['submit_times'] * 100); ?>% (<?php echo $row['ac_times']; ?> / <?php echo $row['submit_times']; ?>)</p>
			<p><a href="discuss_show.php?problem_id=<?php echo $problem_id; ?>">讨论</a></p>
			<h2>提交程序</h2>
			<?php
			if($_SESSION['login']) {
				echo <<<UPLOAD_FORM
			<form action="problem_upload.php">
				<p>文件名：{$row['filename']}.c</p>
				<p><input class="input_upload" name="program" type="file" size="14" /></p>
				<button type="submit">提交</button>
			</form>
UPLOAD_FORM;
			} else
				echo '<p>对不起，您还没有登录。请先<a href="index.php">登录</a>后再提交程序。</p>';
			?>
		</div>
<?php include 'footer.php'; ?>
